package com.scuec.tourismwebsite.controller;

import com.github.pagehelper.PageInfo;
import com.scuec.tourismwebsite.entity.PostComment;
import com.scuec.tourismwebsite.service.PostCommentService;
import com.scuec.tourismwebsite.vo.PComment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
//
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("tour/v1")
public class PostCommentController {
    @Autowired
    private PostCommentService postCommentService;

    @GetMapping("postcomment")
    public List<PComment> getPostComment(@RequestParam Integer post_id){
        return postCommentService.findPCommentById(post_id);
    }

    @GetMapping("PCommentpages")
    public PageInfo<PComment> findPCommentPages(@RequestParam Integer post_id, @RequestParam  Integer pageNum, @RequestParam Integer pageSize){
        return postCommentService.findPCommentPages(post_id, pageNum, pageSize);
    }

    @GetMapping("PCommentpage")
    public PageInfo<PComment> findPCommentPage(@RequestParam Integer post_id, @RequestParam String comment_content, @RequestParam Integer pageNum, @RequestParam Integer pageSize){
        return postCommentService.findPCommentPage(post_id, comment_content, pageNum, pageSize);
    }

    @DeleteMapping("PComment/{comment_id}")
    public Integer deletePCommentById(@PathVariable Integer comment_id){
        return postCommentService.deletePCommentById(comment_id);
    }

    @PostMapping("PComment")
    Integer insertPComment(@RequestBody PostComment postComment){
        return postCommentService.insertPComment(postComment);
    }

}
//1